package com.pan.admin.module.loanUser.contorller;

import com.github.pagehelper.PageHelper;
import com.pan.admin.common.annotation.Log;
import com.pan.admin.common.core.controller.BaseController;
import com.pan.admin.common.core.domain.AjaxResult;
import com.pan.admin.common.core.page.TableDataInfo;
import com.pan.admin.common.enums.BusinessType;
import com.pan.admin.module.channel.service.LoanChannelService;
import com.pan.admin.module.loanProduct.service.LoanProductPlanService;
import com.pan.admin.module.loanProduct.service.LoanProductService;
import com.pan.admin.module.loanUser.entity.LoanUserRegister;
import com.pan.admin.module.loanUser.entity.LoanUserRegisterProduct;
import com.pan.admin.module.loanUser.entity.qo.LoanUserRegisterProductQo;
import com.pan.admin.module.loanUser.entity.qo.LoanUserRegisterQO;
import com.pan.admin.module.loanUser.service.LoanUserRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 用户注册Controller
 * @Author: ghb
 * @Date: 2023/9/7 16:36
 */
@RestController
public class LoanUserRegisterController extends BaseController {

    @Autowired
    private LoanUserRegisterService loanUserRegisterService;
    @Autowired
    private LoanChannelService loanChannelService;
    @Autowired
    private LoanProductService loanProductService;
    @Autowired
    private LoanProductPlanService loanProductPlanService;

    /**
     * 渠道
     */
    @GetMapping("/loanUser/register/listLoanChannel")
    @PreAuthorize("@ss.hasPermi('loanUser:register:list')")
    public AjaxResult listLoanChannel(@RequestParam(required = false) String keyword) {
        return AjaxResult.success(this.loanChannelService.listLoanChannel(keyword));
    }

    /**
     * 主体
     */
    @GetMapping("/loanUser/register/listLoanProduct")
    @PreAuthorize("@ss.hasPermi('loanUser:register:list')")
    public AjaxResult listLoanProduct(@RequestParam(required = false) String keyword) {
        return AjaxResult.success(this.loanProductService.listLoanProduct(keyword));
    }

    /**
     * 计划
     */
    @GetMapping("/loanUser/register/listLoanProductPlan")
    @PreAuthorize("@ss.hasPermi('loanUser:register:list')")
    public AjaxResult listLoanProductPlan(@RequestParam(required = false) List<Long> loanProductId, @RequestParam(required = false) String keyword) {
        return AjaxResult.success(this.loanProductPlanService.listLoanProductPlan(loanProductId, keyword));
    }

    /**
     * 查询用户注册列表
     */
    @GetMapping("/loanUser/register/list")
    @PreAuthorize("@ss.hasPermi('loanUser:register:list')")
    public TableDataInfo list(LoanUserRegisterQO loanUserRegisterQO) {
        startPage();
        // 分页不执行count语句查询总行数
        PageHelper.getLocalPage().count(false);
        List<LoanUserRegister> list = this.loanUserRegisterService.list(loanUserRegisterQO);
        return getDataTable(list);
    }

    /**
     * 查询用户注册列表渠道详情
     */
    @GetMapping("/loanUser/register/details")
    @PreAuthorize("@ss.hasPermi('loanUser:register:details')")
    public TableDataInfo detailsChannelList(LoanUserRegister loanUserRegister) {
        startPage();
        List<LoanUserRegister> list = this.loanUserRegisterService.detailsChannelList(loanUserRegister);
        return getDataTable(list);
    }

    /**
     * 查询用户注册列表机构详情
     */
    @GetMapping("/loanUser/register/listProduct")
    @PreAuthorize("@ss.hasPermi('loanUser:register:listProduct')")
    public TableDataInfo listUserByProductId(LoanUserRegisterProductQo loanUserRegister) {
        startPage();
        List<LoanUserRegisterProduct> list = this.loanUserRegisterService.listUserByProductId(loanUserRegister);
        return getDataTable(list);
    }

    /**
     * 获取用户注册详细信息
     */
    @GetMapping(value = "/loanUser/register/{id}")
    @PreAuthorize("@ss.hasPermi('loanUser:register:list')")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(this.loanUserRegisterService.selectLoanUserRegisterById(id));
    }

    /**
     * 新增用户注册
     */
    @PostMapping("/loanUser/register")
    @PreAuthorize("@ss.hasPermi('loanUser:register:add')")
    @Log(title = "用户注册", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody LoanUserRegister loanUserRegister) {
        return toAjax(this.loanUserRegisterService.insertLoanUserRegister(loanUserRegister));
    }

    /**
     * 修改用户注册
     */
    @PutMapping("/loanUser/register")
    @PreAuthorize("@ss.hasPermi('loanUser:register:edit')")
    @Log(title = "用户注册", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@RequestBody LoanUserRegister loanUserRegister) {
        return toAjax(this.loanUserRegisterService.updateLoanUserRegister(loanUserRegister));
    }
}
